package com.ahs.region.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	/**
	 * appName:应用标题
	 */
	@Value("${app.name}")
	private String appName;

	/**
	 * appDesc : 应用简介
	 */
	@Value("${app.desc}")
	private String appDesc;

	/**
	 * appVersion : 应用版本
	 */
	@Value("${app.version}")
	private String appVersion;
	/**
	 * appVersion : 应用版本
	 */
	@Value("${app.termsOfServiceUrl}")
	private String termsOfServiceUrl;

	/**
	 * license : 应用许可
	 */
	@Value("${app.license}")
	private String license;
	/**
	 * license : 许可地址
	 */
	@Value("${app.licenseUrl}")
	private String licenseUrl;

	/**
	 * contactName : 作者
	 */
	@Value("${app.contact.name}")
	private String contactName;

	/**
	 * contactUrl : 主页
	 */
	@Value("${app.contact.url}")
	private String contactUrl;

	/**
	 * contactEmail : 邮件
	 */
	@Value("${app.contact.email}")
	private String contactEmail;

	@Bean
	public Docket api() {
		return new Docket(DocumentationType.SWAGGER_2).select()
//				 .apis(RequestHandlerSelectors.any())
				.apis(RequestHandlerSelectors.basePackage("com.ahs.region.controller"))
				 .paths(PathSelectors.any())
				.build().apiInfo(apiInfo());
	}

	private ApiInfo apiInfo() {
		ApiInfo apiInfo = new ApiInfo(appName, appDesc, appVersion, termsOfServiceUrl,
				new Contact(contactName, contactUrl, contactEmail), license, licenseUrl);

		return apiInfo;
	}
}
